package com.apex.crm.controller;

import com.apex.crm.base.BaseController;
import com.apex.crm.base.ResultInfo;
import com.apex.crm.query.CustomerLossQuery;
import com.apex.crm.service.CustomerLossService;
import com.apex.crm.service.CustomerReprieveService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author XiaoYang
 * @version 1.0
 * @program: crm
 * @Classname CustomerLossController
 * @description TODO
 * @date 2021/6/10 12:52
 */

@Controller
@RequestMapping("customer_loss")
public class CustomerLossController extends BaseController {

    @Resource
    public CustomerLossService customerLossService;

    @Resource
    private CustomerReprieveService customerReprieveService;


    @GetMapping("index")
    public String index(){
        return "customerLoss/customer_loss";
    }

    //@ApiOperation("流失客户列表")
    @GetMapping("list")
    @ResponseBody
    public Map<String,Object> queryCustomerLossByParams(CustomerLossQuery customerLossQuery){
        return  customerLossService.queryCustomerLossByParams(customerLossQuery);
    }


    //@ApiOperation("暂缓流失界面")
    @GetMapping("toCustomerReprPage")
    public String toCustomerReprPage(Integer id, Model model){
        model.addAttribute("customerLoss",customerLossService.selectByPrimaryKey(id));
        return "customerLoss/customer_rep";
    }


    //@ApiOperation("暂缓流失操作")
    @GetMapping("addOrUpdateCustomerReprPage")
    public String addOrUpdateCustomerReprPage(Integer id,Integer lossId,Model model){
        model.addAttribute("customerRep",customerReprieveService.selectByPrimaryKey(id));
        model.addAttribute("lossId",lossId);
        return "customerLoss/customer_rep_add_update";
    }


    //@ApiOperation("确认流失客户")
    @PostMapping("updateCustomerLossStateById")
    @ResponseBody
    public ResultInfo updateCustomerLossStateById(Integer id, String lossReason){
        customerLossService.updateCustomerLossStateById(id,lossReason);
        return success("客户确认流失成功!");
    }




}
